package com.micangcaihang.micang.mvp.task.ui;

import android.os.Bundle;

import com.micangcaihang.common.base.activity.BaseActivity;
import com.micangcaihang.common.widget.titlebar.TitleBar;
import com.micangcaihang.micang.R;
import com.micangcaihang.micang.databinding.ActivityApplyStopBinding;
import com.micangcaihang.micang.entity.UserInfoSp;
import com.micangcaihang.micang.http.request.ApplyStopRequest;
import com.micangcaihang.micang.mvp.task.contract.ApplyStopContract;
import com.micangcaihang.micang.mvp.task.presenter.ApplyStopPresenter;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/25
 *     update : 2017/07/25
 *     desc   : 申请终止
 *     version: 1.0
 * </pre>
 */

public class ApplyStopActivity extends BaseActivity<ApplyStopPresenter, ActivityApplyStopBinding>
        implements ApplyStopContract.View {

    private ApplyStopRequest mRequest;
    private String id;
    private String reback;//tui退回工单编号

    /**
     * 获取资源文件布局
     *
     * @return 资源布局文件layout
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_apply_stop;
    }

    /**
     * 获取传递的bundle数据
     *
     * @param extras
     */
    @Override
    protected void getBundleExtras(Bundle extras) {
        id = extras.getString("id");
        reback = extras.getString("reback", "0");
    }

    @Override
    public void initView() {
        super.initView();
        String s = getResources().getString(R.string.foramt_task_back_stop_d);
        String title = String.format(s, "");
        if (UserInfoSp.getInstance().getDepartment_id() == 18) {
            title = String.format(s, "风控");
        } else if (UserInfoSp.getInstance().getDepartment_id() == 19) {
            title = String.format(s, "调评");
        }
        mViewBinding.tvTypeTitle.setText(title);
    }

    @Override
    protected void initData() {
        super.initData();
        mRequest = new ApplyStopRequest();
    }

    /**
     * 初始化按钮监听
     */
    @Override
    protected void initListener() {
        mViewBinding.titleBar.setDelegate(new TitleBar.Delegate() {
            @Override
            public void onClickLeftCtv() {
                finish();
            }

            @Override
            public void onClickTitleCtv() {

            }

            @Override
            public void onClickRightCtv() {
                mRequest.setReason(mViewBinding.etReason.getText().toString());
                mRequest.setReback(reback);
                mRequest.setId(id);
                if (UserInfoSp.getInstance().getDepartment_id() == 18) {
                    mRequest.setStep("2");
                } else if (UserInfoSp.getInstance().getDepartment_id() == 19) {
                    mRequest.setStep("3");
                }
                mPresenter.savaApplyStopData(mRequest);
            }

            @Override
            public void onClickRightSecondaryCtv() {

            }
        });
    }

    @Override
    public void onApplyStopSuccess() {
        setResult(RESULT_OK);
        finish();
    }
}
